/******************************************************************************
* File Name:   shell.h
*
* Description: This is the source code for the XMC MCU: UART Shell Example for
*              ModusToolbox. This file is the public interface of shell.c
*              source file.
*
* Related Document: See README.md
*
******************************************************************************
*
* Copyright (c) 2015-2024, Infineon Technologies AG
* All rights reserved.
*
* Boost Software License - Version 1.0 - August 17th, 2003
*
* Permission is hereby granted, free of charge, to any person or organization
* obtaining a copy of the software and accompanying documentation covered by
* this license (the "Software") to use, reproduce, display, distribute,
* execute, and transmit the Software, and to prepare derivative works of the
* Software, and to permit third-parties to whom the Software is furnished to
* do so, all subject to the following:
*
* The copyright notices in the Software and this entire statement, including
* the above license grant, this restriction and the following disclaimer,
* must be included in all copies of the Software, in whole or in part, and
* all derivative works of the Software, unless such copies or derivative
* works are solely in the form of machine-executable object code generated by
* a source language processor.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*****************************************************************************/

#ifndef SHELL_H
#define SHELL_H

#include "ring_buffer.h"

/*******************************************************************************
* Macros
*******************************************************************************/
/* Parameters of shell behaviour */
#define SHELL_PROMPT "SHELL> "
#define SHELL_CMDLINE_SIZE 256
#define SHELL_ARGS_MAX 16

/*******************************************************************************
* Typedefs
*******************************************************************************/
typedef void(*shell_cmd_function_t)(int32_t argc, char **argv);
typedef struct shell_command
{
    char *name;                   /**< @brief Command name (null-terminated string). */
    int8_t min_args;              /**< @brief Minimum number of arguments the command accepts.*/
    int8_t max_args;              /**< @brief Maximum number of arguments the command accepts.*/
    shell_cmd_function_t cmd_ptr; /**< @brief Pointer to the actual command function defined by
                                   *   the @ref shell_cmd_function_t type    */
    char *description;            /**< @brief Brief description of the command (null-terminated string). @n
                                   * This field is used by the @ref shell_help() function.@n */
    char *syntax;                 /**< @brief Syntax of the command (null-terminated string). @n
                                   * This field is used by the @ref shell_help() function.
                                   * The standard command line syntax information
                                   * which will be helpful to describe the possible command
                                   * line parameters in a help display is:
                                   * - @c [] = When a parameter is surrounded with square
                                   * brackets, this means the parameter is optional.
                                   * - @c <> = When a parameter is surrounded with angle
                                   * brackets, this means the parameter is required for
                                   * normal operations of command.
                                   * - @c | = The vertical bar means a choice between
                                   * parameter value is acceptable.*/
} shell_command_t;
extern ring_buffer_t serial_buffer;
#ifdef __cplusplus
extern "C" {
#endif

/*******************************************************************************
* Function prototypes
*******************************************************************************/
void shell_init(const shell_command_t *const cmd_table, void (*init)(void));
void shell_state_machine(void);
void shell_help(void);
int32_t shell_println(const char *format, ... );

#ifdef __cplusplus
}
#endif

#endif
